package com.gpframework.module.order.service.impl;

import com.gpframework.common.enums.YesNoEnum;
import com.gpframework.module.order.domain.GpForwardLogDetail;
import com.gpframework.module.order.domain.vo.GpForwardLogDetailVo;
import com.gpframework.module.order.service.IGpForwardLogDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gpframework.module.order.mapper.GpForwardLogMapper;
import com.gpframework.module.order.domain.GpForwardLog;
import com.gpframework.module.order.domain.vo.GpForwardLogVo;
import com.gpframework.module.order.service.IGpForwardLogService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.Arrays;
import java.util.List;
/**
 * @ClassName GpForwardLog
 * @Author gpframework
 * @Date 2023-08-29
 * @Version 1.0.0
 * @Description 转发记录Service业务层处理
 */
@Service
public class GpForwardLogServiceImpl extends ServiceImpl<GpForwardLogMapper, GpForwardLog> implements IGpForwardLogService {

    @Autowired
    private IGpForwardLogDetailService gpForwardLogDetailService;


    /**
     * @Description 查询列表返回VO 用于返回给前端的列表接口
     * @Author gpframework
     * @Date 2023-08-29
     * @Param [lqw]
     * @Return List<GpForwardLogVo>
     */
    @Override
    public List<GpForwardLogVo> listVo(QueryWrapper<GpForwardLog> lqw) {
        return this.baseMapper.listVo(lqw);
    }

    /**
     * @Description 通过查询详情VO 用于返回给前端的列详情接口
     * @Author gpframework
     * @Date 2023-08-29
     * @Param [id]
     * @Return GpForwardLogVo
     */
    @Override
    public GpForwardLogVo getVoById(Long id) {
        GpForwardLogVo gpForwardLogVo = this.baseMapper.getVo(id);
        if (gpForwardLogVo != null) {
            List<GpForwardLogDetailVo> forwardLogDetailVoList = gpForwardLogDetailService.listVo(new QueryWrapper<GpForwardLogDetail>().eq("gp.forward_log_id", id).eq("gp.del_status", YesNoEnum.NO.getKey()));
            for (GpForwardLogDetailVo gpForwardLogDetailVo : forwardLogDetailVoList) {
                gpForwardLogDetailVo.setAnnexList(Arrays.asList(gpForwardLogDetailVo.getAnnex().split(",")));
            }
            gpForwardLogVo.setForwardLogDetailVoList(forwardLogDetailVoList);
        }
        return gpForwardLogVo;
    }
}
